<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/22/022
 * Time: 18:40
 */

namespace app\common\exception;

use app\common\server\Code;
use Exception;
use think\exception\ErrorException;
use think\exception\Handle as HandleException;
use think\exception\HttpException;
use think\exception\ThrowableError;

class Handle extends HandleException
{
    public function render(Exception $e)
    {
        if(env('environment') == 'local'){
            return parent::render($e);
        }

        if(request()->isAjax()){
            return apiReturn(Code::$error,$e->getMessage());
        }

        if($e instanceof ErrorException || $e instanceof ThrowableError){
            return apiReturn(Code::$syntax_error,$e->getMessage());
        }

        if($e instanceof HttpException || $e instanceof Exception){
            return response('404 not found',404);
        }

        // 其他错误交给系统处理
        return parent::render($e);
    }
}